import { getBannerList, deleteOne, addItem } from '@/api/banner'
export default {
  namespaced: true,
  state: {
    bannerList: []
  },
  mutations: {
    UPDATE_BANNER_LIST (state, data) {
      state.bannerList = data
    }
  },
  actions: {
    getBannerListAction ({ commit }) {
      getBannerList().then(res => {
        commit('UPDATE_BANNER_LIST', res.data.data)
      })
    },
    deleteBannerItemAction (context, params) {
      deleteOne({
        bannerid: params.bannerid
      }).then(() => {
        // acitons中出发别的actions
        context.dispatch('getBannerListAction')
      })
    },
    addBannerListAction (context, params) {
      return new Promise(resolve => {
        addItem(params).then(() => {
          context.dispatch('getBannerListAction')
          resolve()
        })
      })
    }
  }
}
